package org.groupg.filetodb.model;

import cn.hutool.core.date.TimeInterval;
import com.google.common.base.MoreObjects;
import com.google.common.base.Objects;
import org.groupg.filetodb.model.finals.TableRunningStatus;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 单表处理任务执行过程
 */
public class TableRunning {

    /**
     * 处理任务使用的任务对象
     */
    private TaskRunning taskRunning;
    /**
     * 表配置对象
     */
    private TableConfig tableConfig;
    /**
     * 字段配置对象
     */
    private List<ColumnConfig> columnConfigs;

    /**
     * 任务执行状态
     */
    private TableRunningStatus status;
    /**
     * 时间计时器
     */
    private TimeInterval interval = new TimeInterval();
    /**
     * 启动时间
     */
    private LocalDateTime startTime;
    /**
     * 结束时间
     */
    private LocalDateTime endTime;
    /**
     * 时间间隔
     */
    private long duration;
    /**
     * 说明
     */
    private String desc;

    /**
     * 文件行数
     */
    private Long fileRowNum;


    public TableRunning(TaskRunning taskRunning, TableConfig tableConfig, List<ColumnConfig> columnConfigs) {
        this.taskRunning = taskRunning;
        this.tableConfig = tableConfig;
        this.columnConfigs = columnConfigs;
        this.setStatus(TableRunningStatus.READY);
    }

    public TableRunning(TaskRunning taskRunning) {
        this.taskRunning = taskRunning;
        this.setStatus(TableRunningStatus.READY);
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this)
//                .add("taskRunning", taskRunning)
                .add("tableConfig", tableConfig)
                .add("columnConfigs", columnConfigs)
                .add("status", status)
                .add("interval", interval)
                .add("startTime", startTime)
                .add("endTime", endTime)
                .add("duration", duration)
                .add("desc", desc)
                .add("fileRowNum", fileRowNum)
                .toString();
    }

    @Override
    public boolean equals(Object o) {
        if (o == null || getClass() != o.getClass()) return false;
        TableRunning that = (TableRunning) o;
        return getDuration() == that.getDuration() && Objects.equal(getTaskRunning(), that.getTaskRunning()) && Objects.equal(getTableConfig(), that.getTableConfig()) && Objects.equal(getColumnConfigs(), that.getColumnConfigs()) && getStatus() == that.getStatus() && Objects.equal(getInterval(), that.getInterval()) && Objects.equal(getStartTime(), that.getStartTime()) && Objects.equal(getEndTime(), that.getEndTime()) && Objects.equal(getDesc(), that.getDesc()) && Objects.equal(getFileRowNum(), that.getFileRowNum());
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(getTaskRunning(), getTableConfig(), getColumnConfigs(), getStatus(), getInterval(), getStartTime(), getEndTime(), getDuration(), getDesc(), getFileRowNum());
    }

    public TaskRunning getTaskRunning() {
        return taskRunning;
    }

    public void setTaskRunning(TaskRunning taskRunning) {
        this.taskRunning = taskRunning;
    }

    public TableConfig getTableConfig() {
        return tableConfig;
    }

    public void setTableConfig(TableConfig tableConfig) {
        this.tableConfig = tableConfig;
    }

    public List<ColumnConfig> getColumnConfigs() {
        return columnConfigs;
    }

    public void setColumnConfigs(List<ColumnConfig> columnConfigs) {
        this.columnConfigs = columnConfigs;
    }

    public TableRunningStatus getStatus() {
        return status;
    }

    public void setStatus(TableRunningStatus status) {
        this.status = status;
    }

    public TimeInterval getInterval() {
        return interval;
    }

    public void setInterval(TimeInterval interval) {
        this.interval = interval;
    }

    public LocalDateTime getStartTime() {
        return startTime;
    }

    public void setStartTime(LocalDateTime startTime) {
        this.startTime = startTime;
    }

    public LocalDateTime getEndTime() {
        return endTime;
    }

    public void setEndTime(LocalDateTime endTime) {
        this.endTime = endTime;
    }

    public long getDuration() {
        return duration;
    }

    public void setDuration(long duration) {
        this.duration = duration;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public Long getFileRowNum() {
        return fileRowNum;
    }

    public void setFileRowNum(Long fileRowNum) {
        this.fileRowNum = fileRowNum;
    }
}
